package lexer;

public class Token {

	/**
	 * Line and start column of the token
	 */
	private final int line, col;
	/**
	 * Type of the token
	 */
	private final TokenType type;
	/**
	 * Text of the token.
	 */
	private final String text;

	/**
	 * Constructor, creates a Token for given parameters
	 * @param line
	 * @param col
	 * @param type
	 * @param text
	 */
	public Token(int line, int col, TokenType type, String text) {
		this.line = line;
		this.col = col;
		this.type = type;
		this.text = text;
	}

	/**
	 * Returns the line of this token
	 * @return the line of this token
	 */
	public int getLine() {
		return line;
	}

	/**
	 * Returns the start column of this token
	 * @return the start column of this token
	 */
	public int getCol() {
		return col;
	}

	/**
	 * Returns the TokenType of this token, e.g. (1, 1, IDENT, "abc") returns IDENT
	 * @return the TokenType of this token
	 */
	public TokenType getType() {
		return type;
	}

	/**
	 * Returns the text of the token, e.g. (1, 1, IDENT, "abc") returns "abc"
	 * @return the text of the token
	 */
	public String getText() {
		return text;
	}

	@Override
	public String toString() {
		String result = "";
		result += (this.getText().length()>0) ? this.getText() : this.getType().toString();
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Token) {
			Token t = (Token) obj;
			if (this.getType().equals(t.getType()) && this.getText().equals(t.getText())) {
				return true;
			}
		}
		return false;
	}
	
}
